<?php
/*
  [EWEISHOP] Copyright(C) 2017 Elinkint Inc.
  This is NOT a freeware, use is subject to license terms
   
  OpenPlatformMiniProgramCodeTemplate.php 2018-05-30 14:31 cunx $
   
*/

namespace common\library\wechat\openplatform;

use common\component\wechat\Wechat;
use common\library\wechat\WechatApi;

/**
 * 小程序代码模版库管理
 * Class OpenPlatformMiniProgramCodeTemplate
 * @package common\library\wechat\openplatform
 * @author cunx
 */
class OpenPlatformMiniProgramCodeTemplate extends WechatApi
{
    public static $apiType = 'openPlatform';
    public static $forceOpenPlatform = true;

    /**
     * 获取草稿箱内的所有临时代码草稿
     * @return array|bool|void
     * @author cunx
     */
    public static function draftList(){
        $result = self::getInstance()->code_template->getDrafts();
        return Wechat::apiError($result);
    }

    /**
     * 获取代码模版库中的所有小程序代码模版
     * @return array|bool|void
     * @author cunx
     */
    public static function templateList(){
        $result = self::getInstance()->code_template->list();
        return Wechat::apiError($result);
    }

    /**
     * 将草稿箱的草稿选为小程序代码模版
     * @param int $draftId      草稿ID
     * @return array|bool|void
     * @author cunx
     */
    public static function addToTemplate(int $draftId){
        $result = self::getInstance()->code_template->createFromDraft($draftId);
        return Wechat::apiError($result);
    }

    /**
     * 删除指定小程序代码模版
     * @param int $templateId
     * @return array|bool|void
     * @author cunx
     */
    public static function deleteTemplate(int $templateId){
        $result = self::getInstance()->code_template->delete($templateId);
        return Wechat::apiError($result);
    }
}